//判断是否登录成功的文件

#include "staff.h"


//查询数据库是否有账户
int process_user_or_admin_login_request(int newfd,Msg *msg)
{
	printf("------------%s-----------%d.\n",__func__,__LINE__);
	char sql[DATALEN] = {0};
	char *errmsg;
	char **result;
	int nrow,ncolumn;

	msg->info.usertype =  msg->usertype;
	strcpy(msg->info.name,msg->username);
	strcpy(msg->info.passwd,msg->passwd);

	printf("usertype: %#x-----usrname:%s---passwd:%s.\n",msg->info.usertype,msg->info.name,msg->info.passwd);
	sprintf(sql,"select * from usrinfo where usertype=%d and name='%s' and passwd='%s';",msg->info.usertype,msg->info.name,msg->info.passwd);
	if(sqlite3_get_table(db,sql,&result,&nrow,&ncolumn,&errmsg)!= SQLITE_OK){
		printf("---****----%s.\n",errmsg);		
	}else{
		printf("----nrow-----%d,ncolumn-----%d.\n",nrow,ncolumn);		
		if(nrow==0){
			strcpy(msg->recvmsg,"name or passwd failed.\n");
			send(newfd,msg,sizeof(Msg),0);
		}else{
			strcpy(msg->recvmsg,"OK");
			send(newfd,msg,sizeof(Msg),0);
		}
	}
	return 0;	
}
